package com.dao;

import com.entity.Student;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Options;

/**
 * Student DAO 接口，定义对学生表的 CRUD 操作。
 */
@Mapper
public interface StudentDao {
    /** 插入用户并返回受影响的行数 */
    @Insert("INSERT INTO users (username, password, role, created_at, updated_at) " +
            "VALUES (#{username}, #{password}, #{role}, NOW(), NOW())")
    @Options(useGeneratedKeys=true, keyProperty="id")
    int save(Student student);

    /** 根据 ID 查询用户 */
    @Select("SELECT id, username, password, role, created_at AS createTime, updated_at AS updateTime " +
            "FROM users WHERE id = #{id}")
    Student findById(Long id);

    /** 查询所有用户 */
    @Select("SELECT id, username, password, role, created_at AS createTime, updated_at AS updateTime " +
            "FROM users")
    List<Student> findAll();
} 